#include <stdio.h>

static int s_var = 0;

static void __attribute__((naked, optimize("-fomit-frame-pointer")))
ExecInc(int *pValue,  const void *pExitAddr)
{
    asm(".intel_syntax noprefix \n"
        "inc dword ptr [rdi]  \n"
        "jmp rsi     \n"
        ".att_syntax");
}

static void __attribute__((naked, optimize("-fomit-frame-pointer")))
CallEntry(int *pValue, const void *pExitAddr, const void *pExecAddr)
{
    asm(".intel_syntax noprefix \n"
        "jmp rdx     \n"
        ".att_syntax");
}

static void __attribute__((naked, optimize("-fomit-frame-pointer")))
CallExit(void)
{
    asm(".intel_syntax noprefix \n"
        "ret    \n"
        ".att_syntax");
}

int main(int argc, const char* argv[])
{
    while(s_var < 10)
        CallEntry(&s_var, (void*)CallExit, (void*)ExecInc);

    printf("s_var = %d\n", s_var);
}   


